Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[ux]: compile .vyi files #4290

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

sandbubbles
Copy link
Collaborator

What I did

Allowed compiling ".vyi" files with ast,annotated_ast,interface,external_interface,abi flags.
#4232

How I did it

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@charles-cooper charles-cooper changed the title feat[ux]: compile solely vyi feat[ux]: compile .vyi files Oct 15, 2024
@charles-cooper
Copy link
Member

looking good to me. @cyberthirst can you take a look?

@cyberthirst
Copy link
Collaborator

bit unrelated, but if an interface implements other interface and doesn't implement all the methods, we get the following exception:

vyper.exceptions.InterfaceViolation: Contract does not implement all interface functions: foobar()

Contract does not implement.. although it can be triggered via eg vyper -f abi i.vyi

@cyberthirst
Copy link
Collaborator

-f interface doesn't include Flags. is it intended?

@charles-cooper
Copy link
Member

-f interface doesn't include Flags. is it intended?

Not intended. May be the order in which we merged flag and -f interfave PRs

@cyberthirst
Copy link
Collaborator

shouldn't -f interface be basically an identity when called on interface files?

import ITest2

implements: ITest2

def bar() -> uint256:
    ...

def foo() -> uint8:
    ...


def foobar() -> uint8:
    ...

outputs:

# Functions

@external
def bar() -> uint256:
    ...


@external
def foo() -> uint8:
    ...


@external
def foobar() -> uint8:
    ...

ie implements is lost in the translation

@cyberthirst
Copy link
Collaborator

shouldn't -f interface be basically an identity when called on interface files?

import ITest2

implements: ITest2

def bar() -> uint256:
    ...

def foo() -> uint8:
    ...


def foobar() -> uint8:
    ...

outputs:

# Functions

@external
def bar() -> uint256:
    ...


@external
def foo() -> uint8:
    ...


@external
def foobar() -> uint8:
    ...

ie implements is lost in the translation

also, if ITest2.vyi contains a struct (or flag), then those don't propagate for -f interface - not sure whether that's intentional

"""
file = make_file("interface.vyi", interface)
compile_files([file], ["ast", "annotated_ast", "interface", "external_interface", "abi"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to use this here? https://github.com/vyperlang/vyper/pull/4290/files#diff-d428d4c971c9f7166899f6f2d3da5e17ca4478d8d371d803e735d6ee36b39d30R49

so we don't have to maintain the list on 2 places

@cyberthirst
Copy link
Collaborator

 vyper -f external_interface tests/custom/ITest.vyi

# External Interfaces
interface Itest:
    def bar() -> uint256: nonpayable
    def foo() -> uint8: nonpayable
    def foobar() -> uint8: nonpayable

name discrepancy - Itest vs ITest

@charles-cooper
Copy link
Member

this looks ok to me. @cyberthirst what did we decide about the -f interface behavior here?

@charles-cooper
Copy link
Member

i think for -f interface we should not require it to be the identity. it should spit out something that is more or less independent from the file's codebase/context.

but it's not that important. if we can't reach consensus, we can always block the behavior.

@cyberthirst
Copy link
Collaborator

# test__interface.vyi

@external
def foo():
    ...

-f external_interface

IndexError: string index out of range
Error compiling: tests/custom/test__interface.vyi

should crash on name = "".join([x[0].upper() + x[1:] for x in stem.split("_")])

@cyberthirst
Copy link
Collaborator

i think for -f interface we should not require it to be the identity. it should spit out something that is more or less independent from the file's codebase/context.

but it's not that important. if we can't reach consensus, we can always block the behavior.

yeah this sounds reasonable, i was reporting rather for completness

@cyberthirst
Copy link
Collaborator

say we have

flag Foo:
    Blah

@external
def foo() -> Foo:
    ...

then with -f external_interface we'd get:

# External Interfaces
interface Ifile:
    def foo() -> flag Foo('Blah'): nonpayable

which is not valid syntax, is that intentional?

@cyberthirst
Copy link
Collaborator

we can import stateful modules to the vyi files and eg call initializes on them:

# ifile.vyi
import test

initializes: test

@external
def foo(a: test.Foo) -> test.Foo:
    ...
# test.vy

c: uint256

flag Foo:
    Blah

@external
def foo() -> Foo:
    return Foo.Blah

works eg with -f annotated_ast

@charles-cooper
Copy link
Member

say we have

flag Foo:
    Blah

@external
def foo() -> Foo:
    ...

then with -f external_interface we'd get:

# External Interfaces
interface Ifile:
    def foo() -> flag Foo('Blah'): nonpayable

which is not valid syntax, is that intentional?

i think we should fix this -- there was a similar issue with repr for interfaces and/or structs iirc

Copy link

codecov bot commented Dec 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.17%. Comparing base (c8691ac) to head (4c476ad).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4290      +/-   ##
==========================================
- Coverage   91.31%   90.17%   -1.14%     
==========================================
  Files         113      113              
  Lines       16065    16085      +20     
  Branches     2705     2711       +6     
==========================================
- Hits        14670    14505     -165     
- Misses        964     1109     +145     
- Partials      431      471      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cyberthirst cyberthirst added the release - must release blocker label Dec 11, 2024
@sandbubbles
Copy link
Collaborator Author

I’ve made the changes. This should be good for another review.

Comment on lines +451 to +479
unallowed_formats = [
"layout",
"devdoc",
"userdoc",
"archive",
"archive_b64",
"integrity",
"solc_json",
"bb",
"bb_runtime",
"cfg",
"cfg_runtime",
"ir",
"ir_runtime",
"ir_dict",
"ir_runtime_dict",
"method_identifiers",
"metadata",
"asm",
"source_map",
"source_map_runtime",
"bytecode",
"bytecode_runtime",
"blueprint_bytecode",
"opcodes",
"opcodes_runtime",
]

for f in unallowed_formats:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

Suggested change
unallowed_formats = [
"layout",
"devdoc",
"userdoc",
"archive",
"archive_b64",
"integrity",
"solc_json",
"bb",
"bb_runtime",
"cfg",
"cfg_runtime",
"ir",
"ir_runtime",
"ir_dict",
"ir_runtime_dict",
"method_identifiers",
"metadata",
"asm",
"source_map",
"source_map_runtime",
"bytecode",
"bytecode_runtime",
"blueprint_bytecode",
"opcodes",
"opcodes_runtime",
]
for f in unallowed_formats:
for f in OUTPUT_FORMATS: # imported from vyper.compiler
if f in INTERFACE_FORMATS:
continue
# with pytest.raises ...

Comment on lines +145 to +151
if len(interface.flags) > 0:
out += "# Flags\n\n"
for flag in interface.flags.values():
out += f"flag {flag.name}:\n"
for flag_value in flag._flag_members:
out += f" {flag_value}\n"
out += "\n\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyberthirst for future reference, maybe this should have been oos? as it was not in the original scope and could be implemented in a follow up PR

return part[0].upper() + part[1:]
return ""

name = "".join([capitalize_part(x) for x in stem.split("_")])
Copy link
Member

@charles-cooper charles-cooper Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe simpler:

Suggested change
name = "".join([capitalize_part(x) for x in stem.split("_")])
name = stem.title().replace("_", "")

ref: https://stackoverflow.com/questions/44094703

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release - must release blocker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants